/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package soundscovery;

import java.util.Vector;

/**
 *
 * @author Administrator
 */
public class Normalizer {

    public static void normalize(Vector<double[]> inputs, double[] weights, Vector<double[]> output) {    //get mean

        double mean[] = new double[inputs.get(0).length];
        double deviation[] = new double[inputs.get(0).length];

        for (int j = 0; j < inputs.get(0).length; j++) {
            for (int i = 0; i < inputs.size(); i++) {
                mean[j] += inputs.get(i)[j];
            }
            mean[j] /= ((double) inputs.size());

            //subtract mean from values and square them

            for (int i = 0; i < inputs.size(); i++) {
                deviation[j] += (inputs.get(i)[j] - mean[j]) * (inputs.get(i)[j] - mean[j]);
            }

            //find deviation
            deviation[j] = Math.sqrt(deviation[j] / 2.0);

            //normalize attribute values
            for (int i = 0; i < inputs.size(); i++) {
                output.get(i)[j] = (inputs.get(i)[j] - mean[j]) / deviation[j];
            }

        }
    }
}
